package cn.demo.service1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.demo.AbstractController;
import cn.demo.Student;
import cn.demo.User;
import cn.demo.service1.client.HelloService;
import cn.demo.service1.client.Service0Client;

@RestController
public class Service1Controller extends AbstractController {

    @Autowired
    Service0Client service0Client;
    @Autowired
    HelloService helloService;

    @GetMapping("/test/{sleepSec}")
    public String test(
            @PathVariable int sleepSec
    ) {
//        if (1 == 1) {
//            System.out.println(333);
//            throw new RuntimeException("111111111111");
//        }
        return service0Client.test("leo", sleepSec);
    }

    @GetMapping("user")
    public String test() {
//        if (1 == 1) {
//            System.out.println(333);
//            throw new RuntimeException("111111111111");
//        }
        Student stuName = new Student()
                .setStuName("stuName");
        User asd = new User()
                .setId(0)
                .setName("asd")
                .setStudent(stuName);

        System.out.println(asd.toString());
        return service0Client.user(asd);
    }
    
    
    @GetMapping("user-hystrix")
    public String hello() throws Exception {
        return helloService.say("hello");
    }
}
